'''
多窗口切换的常用方法：switch_to.window()
(1)current_window_handle		获取当前窗口句柄
(2)window_handles			获取所有窗口句柄
'''
from selenium import webdriver
from selenium.webdriver.common.by import By
from selenium.webdriver.common.keys import Keys
from time import sleep
from options import options

driver = webdriver.Chrome(options=options)
driver.get(r'https://www.baidu.com/')
sleep(3)
print('当前窗口的句柄是：')
print(driver.current_window_handle)

driver.find_element(By.LINK_TEXT, 'hao123').click()
sleep(3)
print('当前窗口的句柄是：')
print(driver.current_window_handle)

baidu_handle = driver.window_handles[0]
hao123_handle = driver.window_handles[1]
# 切换到 baidu
driver.switch_to.window(baidu_handle)
sleep(3)
# 切换到 hao123
driver.switch_to.window(hao123_handle)
sleep(3)

print('所有窗口的句柄是：')
print(driver.window_handles)

driver.quit()
